/**
 * @Description:
 * @Author 卞鹏飞 <228443632@qq.com>
 * @create 11/08/24 10:55 PM
 */

import { createLazyRouter } from '@shared/base/base-router-view-cache/utils.jsx'
import routes from './routes'
import routerMiddlewareAuth from './middleware-auth'
import routerMiddlewareFullScreen from './middleware-fullscreen.ts'

// types
import { createWebHashHistory } from 'vue-router'
import type { Router } from 'vue-router'
import type { App } from 'vue'

export default {
  _router: undefined as unknown as Router,

  _base: '/',

  install(app: App) {
    // @ts-expect-error
    const router = createLazyRouter({
      base: this._base,
      history: createWebHashHistory(this._base),
      routes: routes,
      switchPathIsRefresh: true
    }) as unknown as Router
    this._router = router

    // console.log('router', router, asyncRoutes)

    routerMiddlewareFullScreen.call(router)

    routerMiddlewareAuth.call(router)

    app.use(router)
  }
}
